package br.com.intelsys.basics.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public abstract class SocketDebug {

	public static void listen(int port) {
		try {
			ServerSocket ss = new ServerSocket(port);
			int i = 0;
			while (true) {
				System.out.println("############# Aguardando ... na porta " + port);
				Socket s = ss.accept();
				i++;
				System.out.println("############# CONECTADO [" + i + "]! ");
				BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
				String line;
				do {
					line = in.readLine();
					System.out.println("[" + i + "] " + line);
				} while (line != null);
				System.out.println("############# DESCONECTADO [" + i + "]! ");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		listen(80);
	}

}
